package com.wanghengzhi.kata;

/**
 * @author wanghengzhi
 * @since 2021/11/14 22:42
 */
public abstract class Goods {
    public static final int MAX_VALUE = 50;
    public static final int MIN_VALUE = 0;
    private final String name;
    protected int quality;
    protected int sellIn;

    public Goods(String name, int quality, int sellIn) {
        this.name = name;
        this.quality = quality;
        this.sellIn = sellIn;
    }

    abstract void updateByDay();

    protected void increaseByOneIfQualityLessThanMaxValue() {
        if (quality < MAX_VALUE) {
            quality = quality + 1;
        }
    }

    protected void decreaseSellInByOne() {
        sellIn = sellIn - 1;
    }

    protected boolean isExpired() {
        return sellIn < MIN_VALUE;
    }

    protected void decreaseQualityIfQualityGreatThanMinValue() {
        if (quality > MIN_VALUE) {
            quality = quality - 1;
        }
    }

    public int getQuality() {
        return quality;
    }

    public int getSellIn() {
        return sellIn;
    }
}
